<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>4.data-属性的用法</title>
</head>

<body>
    <div class="box" data-wsl="你好,世界"></div>
</body>

</html>
<script>
    let Box = document.querySelector(".box");

    // 方式一

    //获取
    // console.log(Box.dataset.wsl); //页面打开就执行

    //设置
    // Box.dataset.wsl="中国,你好"

    //方式二

    //获取
    console.log(Box.getAttribute("data-wsl"));

    //设置
    // Box.setAttribute("data-wsl", "中国,你好");
</script>